package org.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class MainServlet extends HttpServlet{
 /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    private static final String CONTENT_TYPE="text/html;charset=UTF-8";
 //添加用户请求分派
 //Process the HTTP Get request
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws
    ServletException,IOException{
   	 response.setContentType(CONTENT_TYPE);
   	 request.setCharacterEncoding("UTF-8");
   	 PrintWriter out=response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
   	 out.println("<html>");
   	 out.println("<head><title>MainServlet</title></head>");
     out.println("<body bgcolor=\"#ffffff\">");
     out.println("<h3>进入聊天系统.....");
     ServletContext context=getServletContext();
     @SuppressWarnings("unchecked")
	Vector<String> vc=(Vector<String>)context.getAttribute("userlist");
     HttpSession session=request.getSession();
     String username=(String)session.getAttribute("me");
     vc.add(username);
     RequestDispatcher view=request.getRequestDispatcher("/servlet/MessageServlet?me="+username);
     view.forward(request,response);
     out.println("</body>");
     out.println("</html>");
     out.close();
    }
    
    //Process the HTTP Post request
    public void doPost(HttpServletRequest request,HttpServletResponse response)throws
    IOException,ServletException{
 	  doGet(request,response);
   }
}